home *** CD-ROM | disk | FTP | other *** search
/ Clickx 63 / Clickx 63.iso / software / multimedia / mirov204 / Miro_Installer.exe / xulrunner / chrome / toolkit.jar / content / global / viewZoomOverlay.js < prev    next >
Encoding:
JavaScript  |  2008-02-13  |  2.9 KB  |  108 lines

  1. //@line 42 "/e/xr19rel/WINNT_5.2_Depend/mozilla/toolkit/content/viewZoomOverlay.js"
  2.  
  3. /** Document Zoom Management Code
  4.  *
  5.  * To use this, you'll need to have a getBrowser() function.
  6.  **/
  7.  
  8. var ZoomManager = {
  9.   get _prefBranch ZoomManager_get__prefBranch() {
  10.     delete this._prefBranch;
  11.     return this._prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  12.                                         .getService(Components.interfaces.nsIPrefBranch);
  13.   },
  14.  
  15.   get MIN ZoomManager_get_MIN() {
  16.     delete this.MIN;
  17.     return this.MIN = this._prefBranch.getIntPref("zoom.minPercent") / 100;
  18.   },
  19.  
  20.   get MAX ZoomManager_get_MAX() {
  21.     delete this.MAX;
  22.     return this.MAX = this._prefBranch.getIntPref("zoom.maxPercent") / 100;
  23.   },
  24.  
  25.   get useFullZoom ZoomManager_get_useFullZoom() {
  26.     return this._prefBranch.getBoolPref("browser.zoom.full");
  27.   },
  28.  
  29.   set useFullZoom ZoomManager_set_useFullZoom(aVal) {
  30.     this._prefBranch.setBoolPref("browser.zoom.full", aVal);
  31.     return aVal;
  32.   },
  33.  
  34.   get zoom ZoomManager_get_zoom() {
  35.     var markupDocumentViewer = getBrowser().markupDocumentViewer;
  36.  
  37.     return this.useFullZoom ? markupDocumentViewer.fullZoom
  38.                             : markupDocumentViewer.textZoom;
  39.   },
  40.  
  41.   set zoom ZoomManager_set_zoom(aVal) {
  42.     if (aVal < this.MIN || aVal > this.MAX)
  43.       throw Components.results.NS_ERROR_INVALID_ARG;
  44.  
  45.     var markupDocumentViewer = getBrowser().markupDocumentViewer;
  46.  
  47.     if (this.useFullZoom) {
  48.       markupDocumentViewer.textZoom = 1;
  49.       markupDocumentViewer.fullZoom = aVal;
  50.     } else {
  51.       markupDocumentViewer.textZoom = aVal;
  52.       markupDocumentViewer.fullZoom = 1;
  53.     }
  54.  
  55.     return aVal;
  56.   },
  57.  
  58.   get zoomValues ZoomManager_get_zoomValues() {
  59.     var zoomValues = this._prefBranch.getCharPref("toolkit.zoomManager.zoomValues")
  60.                                      .split(",").map(parseFloat);
  61.     zoomValues.sort();
  62.  
  63.     while (zoomValues[0] < this.MIN)
  64.       zoomValues.shift();
  65.  
  66.     while (zoomValues[zoomValues.length - 1] > this.MAX)
  67.       zoomValues.pop();
  68.  
  69.     delete this.zoomValues;
  70.     return this.zoomValues = zoomValues;
  71.   },
  72.  
  73.   enlarge: function ZoomManager_enlarge() {
  74.     var i = this.zoomValues.indexOf(this.snap(this.zoom)) + 1;
  75.     if (i < this.zoomValues.length)
  76.       this.zoom = this.zoomValues[i];
  77.   },
  78.  
  79.   reduce: function ZoomManager_reduce() {
  80.     var i = this.zoomValues.indexOf(this.snap(this.zoom)) - 1;
  81.     if (i >= 0)
  82.       this.zoom = this.zoomValues[i];
  83.   },
  84.  
  85.   reset: function ZoomManager_reset() {
  86.     this.zoom = 1;
  87.   },
  88.  
  89.   toggleZoom: function ZoomManager_toggleZoom() {
  90.     var zoomLevel = this.zoom;
  91.  
  92.     this.useFullZoom = !this.useFullZoom;
  93.     this.zoom = zoomLevel;
  94.   },
  95.  
  96.   snap: function ZoomManager_snap(aVal) {
  97.     var values = this.zoomValues;
  98.     for (var i = 0; i < values.length; i++) {
  99.       if (values[i] >= aVal) {
  100.         if (i > 0 && aVal - values[i - 1] < values[i] - aVal)
  101.           i--;
  102.         return values[i];
  103.       }
  104.     }
  105.     return values[i - 1];
  106.   }
  107. }
  108.